package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;
    /**
     * 客户列表分页展示
     * @param customerName
     * @return
     */
    @Override
    public List<Customer> selectCustomerListByName(String customerName) {
        return customerDao.selectCustomerListByName(customerName);
    }

    /**
     * 客户添加或修改
     */
    @Override
    public void saveAndUpdate(Customer customer) {
        if (customer.getCustomerId()!=null){
            customerDao.UpdateCustomerById(customer);
        }else {
            customerDao.saveCustomer(customer);
        }
    }

    /**
     * 客户删除（支持批量删除）
     */
    @Override
    public void deleteCustomer(String ids) {
        String[] id = ids.split(",");
        for (String s : id) {
            customerDao.deleteCustomer(s);
        }
    }
}
